********************************************************************************
* REPLICATION FILE
* TABLES AND FIGURES
* SECTORAL INTERESTS AND REGIONAL BLOC VOTING IN AFRICAN COUNTRIES
********************************************************************************
* set path to current directory
global path ""
cd "${path}"
global pfigures "${path}/Figures/"

* GRAPH STYLE
	set scheme s1mono
	grstyle init
	grstyle set legend, nobox

	grstyle color background white
	grstyle color ci_area gs12%50
	grstyle color ci_arealine gs12%0
	grstyle anglestyle vertical_tick horizontal

 grstyle yesno draw_major_vgrid yes
	linepalette, n(16)
	grstyle set symbol
	grstyle set lpattern

* A || FIGURES
* FIGURE 1 and FIGURE B1
* The maps were done using QGIS by merging the dataset "[country]_blocs_prod_info" with the corresponding shapefile [Country]Constituencies using the variable "global_id". 

* FIGURE 2 - share of national output
** 2a - Kenya
use "Kenya_blocs_prod_info", clear
drop if morani_bloc == 99
collapse (sum) share_*, by(morani_bloc)
twoway (scatter share_acof morani_bloc) (scatter share_maiz morani_bloc) (scatter share_sugc morani_bloc) (scatter share_teas morani_bloc, ///
	xscale(range(1 4)) xlabel(1 2 3 4, valuelabel) ytitle("Bloc's share of national production") xtitle("Bloc") xlabel(,angle(45)) title("Kenya") ///
	legend(order(1 "Arabica coffee" 2 "Maize" 3 "Sugarcane" 4 "Tea")))
graph export "$pfigures/figure2_Kenya.png", replace

** 2a - Malawi
use "Malawi_blocs_prod_info", clear
drop if morani_bloc == 99
collapse (sum) share_*, by(morani_bloc)
twoway (scatter share_cott morani) (scatter share_maiz morani) (scatter share_sugc morani) (scatter share_teas morani) (scatter share_toba morani, ///
	xscale(range(1 4)) xlabel(1 2 3 4, valuelabel) ytitle("Bloc's share of national production") xtitle("Bloc") xlabel(,angle(45)) title("Malawi") ///
	legend(order(1 "Cotton" 2 "Maize" 3 "Sugarcane" 4 "Tea" 5 "Tobacco") cols(3)))
graph export "$pfigures/figure2_Malawi.png", replace

** 2a - Zambia
use "Zambia_blocs_prod_info", clear
drop if morani_bloc == 99
collapse (sum) share_*, by(morani_bloc)
twoway (scatter share_cott morani) (scatter share_maiz morani) (scatter share_sugc morani) (scatter share_toba morani, ///
	xscale(range(0.5 1 2 2.5)) xlabel(1 2 , valuelabel) ytitle("Bloc's share of national production") xtitle("Bloc") xlabel(,angle(45)) title("Zambia") ///
	legend(order(1 "Cotton" 2 "Maize" 3 "Sugarcane" 4 "Tobacco") cols(2)))
graph export "$pfigures/figure2_Zambia.png", replace

* FIGURE 3 - Ethnic composition of constituencies within blocs
** 3a - Kenya
use "Kenya_blocs_prod_info", clear

foreach var in kalenjin kamba kikuyu kisii luhya luo meru_embu {
	bys morani_bloc: egen mean_bloc_`var' = mean(`var')
	replace mean_bloc_`var' = mean_bloc_`var'*100
}
*
gen largest_gp = kikuyu if central == 1
replace largest_gp = kalenjin if rift_valley == 1
replace largest_gp = luo if western == 1
replace largest_gp = kamba if eastern == 1
replace largest_gp = largest_gp *100
*
gen sh_largest_gp = mean_bloc_kikuyu if central == 1
replace sh_largest_gp = mean_bloc_kalenjin if rift_valley == 1
replace sh_largest_gp = mean_bloc_luo if western == 1
replace sh_largest_gp = mean_bloc_kamba if eastern == 1
*
label def morani_bloc_gpl 1 "C-Kikuyu" 2 "E-Kamba" 3 "RV-Kalenjin" 4 "W-Luo"
label values morani_bloc "morani_bloc_gpl"
label var morani_bloc "Electoral bloc, largest group"
label var sh_largest_gp "Average constituency"
label var largest_gp "Constituency"
*
drop if morani_bloc == 99
twoway (scatter sh_largest_gp morani_bloc, msymbol(diamond) mcolor(black) msize(medlarge)) ///
	(scatter largest_gp morani_bloc, jitter(5,5) msymbol(circle_hollow) xlabel(1 2 3 4, valuelabel) ytitle("Share of population") xtitle("Largest group in bloc") yline(50) xlabel(,angle(45)) title("Kenya"))
	graph export "$pfigures/figure3_Kenya.png", replace

** 3a - Malawi
use "Malawi_blocs_prod_info", clear

foreach var in chewa lomwe ngoni nkhonde sena tonga tumbuka yao {
	bys morani_bloc: egen mean_bloc_`var' = mean(`var')
	replace mean_bloc_`var' = mean_bloc_`var'*100
}
gen largest_gp = chewa if central == 1
replace largest_gp = lomwe if southern == 1
replace largest_gp = tumbuka if northern == 1
replace largest_gp = yao if eastern == 1
replace largest_gp = largest_gp *100
*
gen sh_largest_gp = mean_bloc_chewa if central == 1
replace sh_largest_gp = mean_bloc_lomwe if southern == 1
replace sh_largest_gp = mean_bloc_tumbuka if northern == 1
replace sh_largest_gp = mean_bloc_yao if eastern == 1
*
label def morani_bloc_gpl 1 "C-Chewa" 2 "E-Yao" 3 "N-Tumbuka" 4 "S-Lomwe"
label values morani_bloc "morani_bloc_gpl"
label var morani_bloc "Electoral bloc, largest group"
label var sh_largest_gp "Average constituency"
label var largest_gp "Constituency"
*
drop if morani_bloc == 99
twoway (scatter sh_largest_gp morani_bloc, msymbol(diamond) mcolor(black) msize(medlarge)) ///
	(scatter largest_gp morani_bloc, jitter(5,5) msymbol(circle_hollow) xlabel(1 2 3 4, valuelabel) ytitle("Share of population") xtitle("Largest group in bloc") yline(50) xlabel(,angle(45)) title("Malawi"))
	graph export "$pfigures/figure3_Malawi.png", replace

** 3a - Zambia
use "Zambia_blocs_prod_info", clear
foreach var in bemba bisa chewa kaonde lala lamba lenje lozi lunda luvale mambwe mbunda namwanga ngoni nsenga tonga tumbuka ushi {
	bys morani_bloc: egen mean_bloc_`var' = mean(`var')
	replace mean_bloc_`var' = mean_bloc_`var'*100
}
*
gen largest_gp = tonga if southern == 1
replace largest_gp = bemba if northern_copperbelt == 1
*
gen sh_largest_gp = mean_bloc_tonga if southern == 1
replace sh_largest_gp = mean_bloc_bemba if northern_copperbelt == 1
replace largest_gp = largest_gp *100
*
drop if morani_bloc == 99
*
label def morani_bloc_gpl 1 "NC-Bemba" 2 "S-Tonga"
label values morani_bloc "morani_bloc_gpl"
label var morani_bloc "Electoral bloc, largest group"
label var sh_largest_gp "Average constituency"
label var largest_gp "Constituency"
twoway (scatter sh_largest_gp morani_bloc, msymbol(diamond) mcolor(black) msize(medlarge)) ///
	(scatter largest_gp morani_bloc, jitter(5,5) msymbol(circle_hollow) xscale(range(0.5 1 2 2.5)) xlabel(1 2, valuelabel) ytitle("Share of population") xtitle("Largest group in bloc") yline(50) xlabel(,angle(45)) title("Zambia"))
	graph export "$pfigures/figure3_Zambia.png", replace

* B || TABLES

* B1 || Results on electoral data

*** APPENDIX Table B1 - Persistent Electoral Blocs: Party Voting Patterns (Moran’s I), Number of Constituencies in Persistent Electoral Blocs, and Associated Political Parties (or Candidates), by Election Year

**** Kenya 
use "Kenya_electoral_data.dta", clear
* number of constituencies that are part of the bloc
bys morani_bloc: gen nb_constit = _N
* find most common voting pattern in each bloc 
egen vp_name = concat(winner_name_1997 winner_name_2002 winner_name_2007 winner_name_2013 winner_name_2017), punct(" ")
bys morani_bloc vp_name: gen count_vp = _N
keep morani_bloc count_vp vp_name nb_constit
duplicates drop
gsort morani_bloc - count_vp 
bys morani_bloc: gen nb_line = _n 
keep if nb_line == 1
*
keep morani_bloc nb_constit vp_name
drop if morani_bloc == 99
split vp_name, parse(" ")
rename vp_name1 winner_1997 
rename vp_name2 winner_2002
rename vp_name3 winner_2007
rename vp_name4 winner_2013
rename vp_name5 winner_2017 
order morani_bloc nb_constit winner* 
drop vp_name
// the dataset has been transformed to show contents of the table
drop nb_constit 
reshape long winner_ ,i(morani_bloc) j(year)
rename winner_ winner_bloc
save "Kenya_bloc_winners", replace

**** Malawi 
use "Malawi_electoral_data.dta", clear
* number of constituencies that are part of the bloc
bys morani_bloc: gen nb_constit = _N
* find most common voting pattern in each bloc 
egen vp_name = concat(winner_name_1999 winner_name_2004 winner_name_2009 winner_name_2014 winner_name_2020), punct(" ")
bys morani_bloc vp_name: gen count_vp = _N
keep morani_bloc count_vp vp_name nb_constit
duplicates drop
gsort morani_bloc - count_vp 
bys morani_bloc: gen nb_line = _n 
keep if nb_line == 1
*
keep morani_bloc nb_constit vp_name
drop if morani_bloc == 99
split vp_name, parse(" ")
rename vp_name1 winner_1999 
rename vp_name2 winner_2004
rename vp_name3 winner_2009
rename vp_name4 winner_2014
rename vp_name5 winner_2020 
order morani_bloc nb_constit winner* 
drop vp_name
// the dataset has been transformed to show contents of the table
drop nb_constit 
reshape long winner_ ,i(morani_bloc) j(year)
rename winner_ winner_bloc
save "Malawi_bloc_winners", replace

**** Zambia 
use "Zambia_electoral_data.dta", clear
* number of constituencies that are part of the bloc
bys morani_bloc: gen nb_constit = _N
* find most common voting pattern in each bloc 
egen vp_name = concat(winner_name_1991 winner_name_1996 winner_name_2001 winner_name_2006 winner_name_2011 winner_name_2016 winner_name_2021), punct(" ")
bys morani_bloc vp_name: gen count_vp = _N
keep morani_bloc count_vp vp_name nb_constit
duplicates drop
gsort morani_bloc - count_vp 
bys morani_bloc: gen nb_line = _n 
keep if nb_line == 1
*
keep morani_bloc nb_constit vp_name
drop if morani_bloc == 99
split vp_name, parse(" ")
rename vp_name1 winner_1991 
rename vp_name2 winner_1996
rename vp_name3 winner_2001
rename vp_name4 winner_2006
rename vp_name5 winner_2011 
rename vp_name6 winner_2016 
rename vp_name7 winner_2021 
order morani_bloc nb_constit winner* 
drop vp_name
// the dataset has been transformed to show contents of the table
drop nb_constit 
reshape long winner_ ,i(morani_bloc) j(year)
rename winner_ winner_bloc
save "Zambia_bloc_winners", replace

*** APPENDIX Table B2 - Average constituency-level vote share in local Moran’s I cluster for each election
**** Kenya 
use "Kenya_electoral_data.dta", clear
*
preserve
local year 1997
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_dp_`year' if winner_name_`year' == "DP"
replace winner_share = votes_kanu_`year' if winner_name_`year' == "KANU"
replace winner_share = votes_ndpk_`year' if winner_name_`year' == "NDPK"
replace winner_share = votes_sdp_`year' if winner_name_`year' == "SDP" 
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2002
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_narc_`year' if winner_name_`year' == "NARC"
replace winner_share = votes_kanu_`year' if winner_name_`year' == "KANU"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2007
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_pnu_`year' if winner_name_`year' == "PNU"
replace winner_share = votes_odm_`year' if winner_name_`year' == "ODM"
replace winner_share = votes_odmk_`year' if winner_name_`year' == "ODM-K"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2013
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_pres_kenyatta_`year' if winner_name_`year' == "pres_kenyatta"
replace winner_share = votes_pres_odinga_`year' if winner_name_`year' == "pres_odinga"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2017
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_pres_kenyatta_`year' if winner_name_`year' == "pres_kenyatta"
replace winner_share = votes_pres_odinga_`year' if winner_name_`year' == "pres_odinga"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
use `t1997', clear 
foreach year in 2002 2007 2013 2017 {
append using `t`year''
}
merge m:1 morani_bloc year using "Kenya_bloc_winners", nogen
drop if morani_bloc == 99 // non-bloc constituencies not included
keep if winner_name == winner_bloc
drop winner_name winner_bloc
*
reshape wide winner_share, i(morani_bloc) j(year)
// the dataset has been transformed to show contents of the table

**** Malawi 
use "Malawi_electoral_data.dta", clear
*
preserve
local year 1999
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_mcp_a_`year' if winner_name_`year' == "mcp-aford"
replace winner_share = votes_udf_`year' if winner_name_`year' == "udf"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2004
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_mcp_`year' if winner_name_`year' == "mcp"
replace winner_share = votes_udf_`year' if winner_name_`year' == "udf"
replace winner_share = votes_mgwirizano_`year' if winner_name_`year' == "mgwirizano"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2009
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_mcp_`year' if winner_name_`year' == "mcp"
replace winner_share = votes_dpp_`year' if winner_name_`year' == "dpp"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2014
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_mcp_`year' if winner_name_`year' == "mcp"
replace winner_share = votes_dpp_`year' if winner_name_`year' == "dpp"
replace winner_share = votes_udf_`year' if winner_name_`year' == "udf"
replace winner_share = votes_pp_`year' if winner_name_`year' == "pp"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2020
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_mcp_`year' if winner_name_`year' == "mcp"
replace winner_share = votes_dpp_`year' if winner_name_`year' == "dpp"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
use `t1999', clear 
foreach year in 2004 2009 2014 2020 {
append using `t`year''
}
merge m:1 morani_bloc year using "Malawi_bloc_winners", nogen
drop if morani_bloc == 99 // non-bloc constituencies not included
keep if winner_name == winner_bloc
drop winner_name winner_bloc
*
reshape wide winner_share, i(morani_bloc) j(year)
// the dataset has been transformed to show contents of the table

**** Zambia
use "Zambia_electoral_data.dta", clear
*
preserve
local year 1991
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_mmd_`year' if winner_name_`year' == "mmd"
replace winner_share = votes_unip_`year' if winner_name_`year' == "unip"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 1996
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_mmd_`year' if winner_name_`year' == "mmd"
replace winner_share = votes_unip_`year' if winner_name_`year' == "unip"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2001
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_mmd_`year' if winner_name_`year' == "mmd"
replace winner_share = votes_unip_`year' if winner_name_`year' == "unip"
replace winner_share = votes_upnd_`year' if winner_name_`year' == "upnd"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2006
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_mmd_`year' if winner_name_`year' == "mmd"
replace winner_share = votes_upnd_`year' if winner_name_`year' == "upnd"
replace winner_share = votes_pf_`year' if winner_name_`year' == "pf"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2011
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_mmd_`year' if winner_name_`year' == "mmd"
replace winner_share = votes_upnd_`year' if winner_name_`year' == "upnd"
replace winner_share = votes_pf_`year' if winner_name_`year' == "pf"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2016
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_mmd_`year' if winner_name_`year' == "mmd"
replace winner_share = votes_upnd_`year' if winner_name_`year' == "upnd"
replace winner_share = votes_pf_`year' if winner_name_`year' == "pf"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2021
keep if core_bloc_`year' == 1 & mi_`year'!= ""
collapse votes*, by(winner_name_`year' morani_bloc)
gen year = `year'
gen winner_share = votes_upnd_`year' if winner_name_`year' == "upnd"
replace winner_share = votes_pf_`year' if winner_name_`year' == "pf"
rename winner_name_`year' winner_name
keep morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
use `t1991', clear 
foreach year in 1996 2001 2006 2011 2016 2021 {
append using `t`year''
}
merge m:1 morani_bloc year using "Zambia_bloc_winners", nogen
drop if morani_bloc == 99 // non-bloc constituencies not included
keep if winner_name == winner_bloc
drop winner_name winner_bloc
*
reshape wide winner_share, i(morani_bloc) j(year)
// the dataset has been transformed to show contents of the table


* B2 || Results on production data

** KENYA - all country-specific tables
*** Table 1 - production profile of constituencies within blocs and blocs’ production profile: Share of national output, production per areal unit, and share of constituencies within bloc that produce the crop
use "Kenya_blocs_prod_info", clear

* (a) Specialisation measure
preserve
foreach crop in acof rcof maiz sugc teas {
// above 75p, unconditional distribution of total production (including non-bloc constituencies)
	sum total_`crop', d
	gen above_75p_`crop' = 1 if total_`crop' > `r(p75)'
	recode above_75p_`crop' (.=0)
}
gen nb_constit = 1
collapse (sum) above_75p_* nb_constit, by(morani_bloc)
foreach crop in acof rcof maiz sugc teas {
	gen share_above_75p_`crop' = (above_75p_`crop' / nb_constit)*100
}
drop if morani_bloc == 99 // non-bloc constituencies not in table
*
keep morani_bloc share*
rename share_above_75p_* *
gen spemeasure = "Central, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 1
replace spemeasure = "Eastern, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 2
replace spemeasure = "Rift Valley, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 3
replace spemeasure = "Western, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 4
duplicates drop
*
drop if morani_bloc == 99
duplicates drop
tempfile 1 
save `1'
restore 

* (b) Concentration of production in bloc
preserve
foreach crop in acof rcof maiz sugc teas {
// total production in bloc 
	bys morani_bloc: egen total_bloc_`crop' = total(total_`crop')
	egen total_country_`crop' = total(total_`crop')
}

keep morani_bloc total_country_* total_bloc* 
foreach crop in acof rcof maiz sugc teas {
	gen share_countryprod_bloc_`crop' = (total_bloc_`crop' / total_country_`crop')*100
}
keep morani_bloc share_countryprod_bloc_*
rename share_countryprod_bloc_* *
gen spemeasure = "Central, (b) Concentration of production in bloc " if morani_bloc == 1
replace spemeasure = "Eastern, (b) Concentration of production in bloc " if morani_bloc == 2
replace spemeasure = "Rift Valley, (b) Concentration of production in bloc " if morani_bloc == 3
replace spemeasure = "Western, (b) Concentration of production in bloc " if morani_bloc == 4
drop if morani_bloc == 99
duplicates drop
tempfile 1a 
save `1a'
restore 


* (c) Production per areal unit in bloc 
preserve
keep morani_bloc areal_unit_acof_bloc areal_unit_rcof_bloc areal_unit_maiz_bloc areal_unit_sugc_bloc areal_unit_teas_bloc 
rename areal_unit_*_bloc *
gen spemeasure = "Central, (c) Production per areal unit in bloc" if morani_bloc == 1
replace spemeasure = "Eastern, (c) Production per areal unit in bloc" if morani_bloc == 2
replace spemeasure = "Rift Valley, (c) Production per areal unit in bloc" if morani_bloc == 3
replace spemeasure = "Western, (c) Production per areal unit in bloc" if morani_bloc == 4
drop if morani_bloc == 99
duplicates drop
order spemeasure acof rcof maiz sugc teas
tempfile 1b 
save `1b'
restore 


* (d) Prevalence (among constituencies in bloc)
foreach crop in acof rcof maiz sugc teas {
	gen nonnull_`crop' = 1 if total_`crop' > 0
	recode nonnull_`crop' (. =0)
}
gen nb_constit = 1 
collapse (sum) nonnull_* nb_constit, by(morani_bloc)
foreach crop in acof rcof maiz sugc teas {
	gen share_nonnull_`crop' = (nonnull_`crop' / nb_constit)*100
}
keep morani_bloc share*
rename share_nonnull_* *
gen spemeasure = "Central,  (d) Prevalence (% producer constituencies)" if morani_bloc == 1
replace spemeasure = "Eastern,  (d) Prevalence (% producer constituencies)" if morani_bloc == 2
replace spemeasure = "Rift Valley,  (d) Prevalence (% producer constituencies)" if morani_bloc == 3
replace spemeasure = "Western,  (d) Prevalence (% producer constituencies)" if morani_bloc == 4
drop if morani_bloc == 99
duplicates drop
*
append using `1'
append using `1a'
append using `1b'
drop morani_bloc 
order spemeasure 
sort spemeasure

// the dataset has been transformed to show contents of the table

*** Table 4 - Agricultural Production Profile of constituencies within blocs, by type of ethnic majority
use "Kenya_blocs_prod_info", clear

// compute share of the ethnic majority at bloc level within each constituency
gen largest_gp = kikuyu if central == 1
replace largest_gp = kalenjin if rift_valley == 1
replace largest_gp = luo if western == 1
replace largest_gp = kamba if eastern == 1

// split blocs by ethnic majority
gen morani_bloc_ethmaj = "Central - Kikuyu" if central == 1 & largest_gp >= 0.5
replace morani_bloc_ethmaj = "Central - non-Kikuyu" if central == 1 & largest_gp < 0.5
replace morani_bloc_ethmaj = "Eastern - Kamba" if eastern == 1 & largest_gp >= 0.5
replace morani_bloc_ethmaj = "Eastern - non-Kamba" if eastern == 1 & largest_gp < 0.5
replace morani_bloc_ethmaj = "Rift Valley - Kalenjin" if rift_valley == 1 & largest_gp >= 0.5
replace morani_bloc_ethmaj = "Rift Valley - non-Kalenjin" if rift_valley == 1 & largest_gp < 0.5
replace morani_bloc_ethmaj = "Western - Luo" if western == 1 & largest_gp >= 0.5
replace morani_bloc_ethmaj = "Western - non-Luo" if western == 1 & largest_gp < 0.5
replace morani_bloc_ethmaj = "todrop" if eastern == 1 // all constituencies have Kamba majority: not displayed in the table as no variation
replace morani_bloc_ethmaj = "todrop" if morani_bloc == 99 // non-bloc constituencies not in table

*
foreach crop in acof rcof maiz sugc teas {
// above 75p, unconditional distribution of total production (including non-bloc constituencies)
	sum total_`crop', d
	gen above_75p_`crop' = 1 if total_`crop' > `r(p75)'
	recode above_75p_`crop' (.=0)
}
gen nb_constit = 1
collapse (sum) above_75p_* nb_constit, by(morani_bloc_ethmaj)
foreach crop in acof rcof maiz sugc teas {
	gen share_above_75p_`crop' = (above_75p_`crop' / nb_constit)*100
}
*
*
keep morani_bloc_ethmaj share* nb_constit
rename share_above_75p_* *
gen spemeasure = morani_bloc_ethmaj + ", (a) Specialisation (% top-producing constituencies)"
*
drop if morani_bloc_ethmaj == "todrop"
drop morani_bloc_ethmaj
order spemeasure
// the dataset has been transformed to show contents of the table


*** APPENDIX Table C1 - Robustness checks: Using alternative specifications to assess the production profile of constituencies within blocs
use "Kenya_blocs_prod_info", clear
*
preserve
foreach crop in acof rcof maiz sugc teas {
// above 75p, unconditional distribution of production per capita
	sum pop_`crop', d
	gen above_75p_`crop' = 1 if pop_`crop' > `r(p75)'
	recode above_75p_`crop' (.=0)
}
gen nb_constit = 1
collapse (sum) above_75p_* nb_constit, by(morani_bloc)
foreach crop in acof rcof maiz sugc teas {
	gen share_above_75p_`crop' = (above_75p_`crop' / nb_constit)*100
}
keep morani_bloc share*
rename share_above_75p_* *
gen spemeasure = "Central, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 1
replace spemeasure = "Eastern, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 2
replace spemeasure = "Rift Valley, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 3
replace spemeasure = "Western, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 4
duplicates drop
tempfile 1a
save `1a'
restore
*
foreach crop in acof rcof maiz sugc teas {
// above 75p, unconditional distribution of specialisation ratio
	sum areal_unit_`crop', d
	gen above_75p_`crop' = 1 if areal_unit_`crop' > `r(p75)'
	recode above_75p_`crop' (.=0)
}
gen nb_constit = 1
collapse (sum) above_75p_* nb_constit, by(morani_bloc)
foreach crop in acof rcof maiz sugc teas {
	gen share_above_75p_`crop' = (above_75p_`crop' / nb_constit)*100
}
keep morani_bloc share*
rename share_above_75p_* *
gen spemeasure = "Central, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 1
replace spemeasure = "Eastern, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 2
replace spemeasure = "Rift Valley, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 3
replace spemeasure = "Western, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 4
duplicates drop
*
append using `1a'
*
drop morani_bloc
order spemeasure
// the dataset has been transformed to show contents of the table

*** APPENDIX Table B5 - Correlation between constituency-level total production and share of population employed in agriculture
use "Kenya_blocs_prod_info", clear
global croplist acof maiz sugc teas
local i = 0
mat A = J(2,4,.)
foreach crop in $croplist {
	local i = `i' + 1
	pwcorr total_`crop' agric ,sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[1,`i'] = C[2,1]
	mat A[2,`i'] = sig[2,1]
}
matrix colnames A = Arabica Maize Sugarcane Teas
matrix rownames A = Share_agric P-value
mat list A

** MALAWI - all country-specific tables

*** Table 2 - production profile of constituencies within blocs and blocs’ production profile: Share of national output, production per areal unit, and share of constituencies within bloc that produce the crop
use "Malawi_blocs_prod_info", clear

* (a) Specialisation measure
preserve
foreach crop in cott maiz sugc teas toba {
// above 75p, unconditional distribution of total production (including non-bloc constituencies)
	sum total_`crop', d
	gen above_75p_`crop' = 1 if total_`crop' > `r(p75)'
	recode above_75p_`crop' (.=0)
}
gen nb_constit = 1
collapse (sum) above_75p_* nb_constit, by(morani_bloc)
foreach crop in cott maiz sugc teas toba {
	gen share_above_75p_`crop' = (above_75p_`crop' / nb_constit)*100
}
keep morani_bloc share*
rename share_above_75p_* *
gen spemeasure = "Central, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 1
replace spemeasure = "Eastern, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 2
replace spemeasure = "Northern, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 3
replace spemeasure = "Southern, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 4
duplicates drop
drop if morani_bloc == 99
duplicates drop
tempfile 1
save `1'
restore

* (b) Concentration of production in bloc
preserve
foreach crop in cott maiz sugc teas toba {
// total production in bloc 
	bys morani_bloc: egen total_bloc_`crop' = total(total_`crop')
	egen total_country_`crop' = total(total_`crop')
}

keep morani_bloc total_country_* total_bloc* 
foreach crop in cott maiz sugc teas toba {
	gen share_countryprod_bloc_`crop' = (total_bloc_`crop' / total_country_`crop')*100
}
keep morani_bloc share_countryprod_bloc_*
rename share_countryprod_bloc_* *
gen spemeasure = "Central, (b) Concentration of production in bloc " if morani_bloc == 1
replace spemeasure = "Eastern, (b) Concentration of production in bloc " if morani_bloc == 2
replace spemeasure = "Northern, (b) Concentration of production in bloc " if morani_bloc == 3
replace spemeasure = "Southern, (b) Concentration of production in bloc " if morani_bloc == 4
drop if morani_bloc == 99
duplicates drop
tempfile 1a 
save `1a'
restore 


* (c) Production per areal unit in bloc 
preserve
keep morani_bloc areal_unit_cott_bloc areal_unit_maiz_bloc areal_unit_sugc_bloc areal_unit_teas_bloc areal_unit_toba_bloc
rename areal_unit_*_bloc *
gen spemeasure = "Central, (c) Production per areal unit in bloc " if morani_bloc == 1
replace spemeasure = "Eastern, (c) Production per areal unit in bloc" if morani_bloc == 2
replace spemeasure = "Northern, (c) Production per areal unit in bloc" if morani_bloc == 3
replace spemeasure = "Southern, (c) Production per areal unit in bloc" if morani_bloc == 4
drop if morani_bloc == 99
duplicates drop
order spemeasure cott maiz sugc teas toba
tempfile 1b 
save `1b'
restore 

* (d) Prevalence (among constituencies in bloc)
foreach crop in cott maiz sugc teas toba {
	gen nonnull_`crop' = 1 if total_`crop' > 0
	recode nonnull_`crop' (. =0)
}
gen nb_constit = 1 
collapse (sum) nonnull_* nb_constit, by(morani_bloc)
foreach crop in cott maiz sugc teas toba {
	gen share_nonnull_`crop' = (nonnull_`crop' / nb_constit)*100
}
keep morani_bloc share*
rename share_nonnull_* *
gen spemeasure = "Central,  (d) Prevalence (% producer constituencies)" if morani_bloc == 1
replace spemeasure = "Eastern, (d) % Prevalance (among constituencies in bloc)" if morani_bloc == 2
replace spemeasure = "Northern, (d) % Prevalance (among constituencies in bloc)" if morani_bloc == 3
replace spemeasure = "Southern, (d) % Prevalance (among constituencies in bloc)" if morani_bloc == 4
drop if morani_bloc == 99
duplicates drop
*
append using `1'
append using `1a'
append using `1b'
drop morani_bloc 
order spemeasure 
sort spemeasure

// the dataset has been transformed to show contents of the table


*** Table 5 - Agricultural Production Profile of constituencies within blocs, by type of ethnic majority
use "Malawi_blocs_prod_info", clear

// compute share of the ethnic majority at bloc level within each constituency
gen largest_gp = chewa if central == 1
replace largest_gp = lomwe if southern == 1
replace largest_gp = tumbuka if northern == 1
replace largest_gp = yao if eastern == 1

// split blocs by ethnic majority
 gen morani_bloc_ethmaj = "Central - Chewa" if central == 1 & largest_gp >= 0.5
replace morani_bloc_ethmaj = "Central - other" if central == 1 & largest_gp < 0.5
replace morani_bloc_ethmaj = "Eastern - Yao" if eastern == 1 & largest_gp >= 0.5
replace morani_bloc_ethmaj = "Eastern - other" if eastern == 1 & largest_gp < 0.5
replace morani_bloc_ethmaj = "Northern - Tumbuka" if northern == 1 & largest_gp >= 0.5
replace morani_bloc_ethmaj = "Northern - other" if northern == 1 & largest_gp < 0.5
replace morani_bloc_ethmaj = "Southern - Lomwe" if southern == 1 & largest_gp >= 0.5
replace morani_bloc_ethmaj = "Southern - other" if southern == 1 & largest_gp < 0.5
replace morani_bloc_ethmaj = "todrop" if morani_bloc == 99 // non-bloc constituencies not in table
*
foreach crop in cott maiz sugc teas toba {
// above 75p, unconditional distribution of total production (including non-bloc constituencies)
	sum total_`crop', d
	gen above_75p_`crop' = 1 if total_`crop' > `r(p75)'
	recode above_75p_`crop' (.=0)
}
gen nb_constit = 1
collapse (sum) above_75p_* nb_constit, by(morani_bloc_ethmaj)
foreach crop in cott maiz sugc teas toba {
	gen share_above_75p_`crop' = (above_75p_`crop' / nb_constit)*100
}
keep morani_bloc_ethmaj share* nb_constit
rename share_above_75p_* *
gen spemeasure = morani_bloc_ethmaj + ", (a) Specialisation (% top-producing constituencies)"
drop if morani_bloc_ethmaj == "todrop"

drop morani_bloc_ethmaj
duplicates drop
order spemeasure


*** APPENDIX Table C2 - Robustness checks: Using alternative specifications to assess the production profile of constituencies within blocs
use "Malawi_blocs_prod_info", clear
*
preserve
foreach crop in cott maiz sugc teas toba {
// above 75p, unconditional distribution of production per capita
	sum pop_`crop', d
	gen above_75p_`crop' = 1 if pop_`crop' > `r(p75)'
	recode above_75p_`crop' (.=0)
}
gen nb_constit = 1
collapse (sum) above_75p_* nb_constit, by(morani_bloc)
foreach crop in cott maiz sugc teas toba {
	gen share_above_75p_`crop' = (above_75p_`crop' / nb_constit)*100
}
keep morani_bloc share*
rename share_above_75p_* *
gen spemeasure = "Central, prod pc, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 1
replace spemeasure = "Eastern, prod pc, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 2
replace spemeasure = "Northern, prod pc, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 3
replace spemeasure = "Southern, prod pc, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 4
duplicates drop
tempfile 1a
save `1a'
restore
*
foreach crop in cott maiz sugc teas toba {
// above 75p, unconditional distribution of specialisation ratio
	sum areal_unit_`crop', d
	gen above_75p_`crop' = 1 if areal_unit_`crop' > `r(p75)'
	recode above_75p_`crop' (.=0)
}
gen nb_constit = 1
collapse (sum) above_75p_* nb_constit, by(morani_bloc)
foreach crop in cott maiz sugc teas toba {
	gen share_above_75p_`crop' = (above_75p_`crop' / nb_constit)*100
}
keep morani_bloc share*
rename share_above_75p_* *
gen spemeasure = "Central, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 1
replace spemeasure = "Eastern, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 2
replace spemeasure = "Northern, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 3
replace spemeasure = "Southern, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 4
duplicates drop
*
append using `1a'
*
drop morani_bloc
order spemeasure
// the dataset has been transformed to show contents of the table

*** APPENDIX Table B5 - Correlation between constituency-level total production and share of population employed in agriculture
use "Malawi_blocs_prod_info", clear
global croplist cott maiz sugc teas toba
local i = 0
mat A = J(2,5,.)

foreach crop in $croplist {
	local i = `i' + 1
	pwcorr total_`crop' agric,sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[1,`i'] = C[2,1]
	mat A[2,`i'] = sig[2,1]
}
matrix colnames A = Cotton Maize Sugarcane Teas Tobacco
matrix rownames A = Share_agric P-value
mat list A

** ZAMBIA - all country-specific tables

*** Table 3 - production profile of constituencies within blocs and blocs’ production profile: Share of national output, production per areal unit, and share of constituencies within bloc that produce the crop
use "Zambia_blocs_prod_info", clear
* (a) Specialisation measure
preserve
foreach crop in cott maiz sugc toba {
// above 75p, unconditional distribution of total production (including non-bloc constituencies)
	sum total_`crop', d
	gen above_75p_`crop' = 1 if total_`crop' > `r(p75)'
	recode above_75p_`crop' (.=0)
}
gen nb_constit = 1
collapse (sum) above_75p_* nb_constit, by(morani_bloc)
foreach crop in cott maiz sugc toba {
	gen share_above_75p_`crop' = (above_75p_`crop' / nb_constit)*100
}
keep morani_bloc share*
rename share_above_75p_* *
gen spemeasure = "Northern-C, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 1
replace spemeasure = "Southern, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 2
duplicates drop
drop if morani_bloc == 99
*
drop morani_bloc
order spemeasure
tempfile 1
save `1'
restore 

* (b) Concentration of production in bloc
preserve
foreach crop in cott maiz sugc toba {
// total production in bloc 
	bys morani_bloc: egen total_bloc_`crop' = total(total_`crop')
	egen total_country_`crop' = total(total_`crop')
}

keep morani_bloc total_country_* total_bloc* 
foreach crop in cott maiz sugc toba {
	gen share_countryprod_bloc_`crop' = (total_bloc_`crop' / total_country_`crop')*100
}
keep morani_bloc share_countryprod_bloc_*
rename share_countryprod_bloc_* *
gen spemeasure = "Northern-C, (b) Concentration of production in bloc " if morani_bloc == 1
replace spemeasure = "Southern, (b) Concentration of production in bloc " if morani_bloc == 2
drop if morani_bloc == 99
duplicates drop
tempfile 1a 
save `1a'
restore 

* (c) Production per areal unit in bloc 
preserve
keep morani_bloc areal_unit_cott_bloc areal_unit_maiz_bloc areal_unit_sugc_bloc areal_unit_toba_bloc
rename areal_unit_*_bloc *
gen spemeasure = "Northern-C, (c) Production per areal unit in bloc " if morani_bloc == 1
replace spemeasure = "Southern, (c) Production per areal unit in bloc " if morani_bloc == 2
drop if morani_bloc == 99
duplicates drop
order spemeasure cott maiz sugc toba
tempfile 1b 
save `1b'
restore 

* (d) Prevalence (among constituencies in bloc)
foreach crop in cott maiz sugc toba {
	gen nonnull_`crop' = 1 if total_`crop' > 0
	recode nonnull_`crop' (. =0)
}
gen nb_constit = 1 
collapse (sum) nonnull_* nb_constit, by(morani_bloc)
foreach crop in cott maiz sugc toba {
	gen share_nonnull_`crop' = (nonnull_`crop' / nb_constit)*100
}
keep morani_bloc share*
rename share_nonnull_* *
gen spemeasure = "Northern-C,  (d) Prevalence (% producer constituencies)" if morani_bloc == 1
replace spemeasure = "Southern, (d) % Prevalance (among constituencies in bloc)" if morani_bloc == 2
drop if morani_bloc == 99
duplicates drop
*
append using `1'
append using `1a'
append using `1b'
drop morani_bloc 
order spemeasure 
sort spemeasure
// the dataset has been transformed to show contents of the table


*** Table 6 - Agricultural Production Profile of constituencies within blocs, by type of ethnic majority
use "Zambia_blocs_prod_info", clear

// compute share of the ethnic majority at bloc level within each constituency
gen largest_gp = tonga if southern == 1
replace largest_gp = bemba if northern_copperbelt == 1

// split blocs by ethnic majority
gen morani_bloc_ethmaj = "NorthernC - Bemba" if northern_copperbelt == 1 & largest_gp >= 0.5
replace morani_bloc_ethmaj = "NorthernC - other" if northern_copperbelt == 1 & largest_gp < 0.5
replace morani_bloc_ethmaj = "Southern - Tonga" if southern == 1 & largest_gp >= 0.5
replace morani_bloc_ethmaj = "Southern - other" if southern == 1 & largest_gp < 0.5
replace morani_bloc_ethmaj = "todrop" if morani_bloc == 99

foreach crop in cott maiz sugc toba {
// above 75p, unconditional distribution of total production (including non-bloc constituencies)
	sum total_`crop', d
	gen above_75p_`crop' = 1 if total_`crop' > `r(p75)'
	recode above_75p_`crop' (.=0)
}
gen nb_constit = 1
collapse (sum) above_75p_* nb_constit, by(morani_bloc_ethmaj)
foreach crop in cott maiz sugc toba {
	gen share_above_75p_`crop' = (above_75p_`crop' / nb_constit)*100
}
keep morani_bloc_ethmaj share* nb_constit
rename share_above_75p_* *
gen spemeasure = morani_bloc_ethmaj + ", (a) Specialisation (% top-producing constituencies)"
drop if morani_bloc_ethmaj == "todrop"

drop morani_bloc_ethmaj
duplicates drop
order spemeasure
// the dataset has been transformed to show contents of the table



*** APPENDIX Table C3 - Robustness checks: Using alternative specifications to assess the production profile of constituencies within blocs
use "Zambia_blocs_prod_info", clear
*
preserve
foreach crop in cott maiz sugc toba {
// above 75p, unconditional distribution of production per capita
	sum pop_`crop', d
	gen above_75p_`crop' = 1 if pop_`crop' > `r(p75)'
	recode above_75p_`crop' (.=0)
}
gen nb_constit = 1
collapse (sum) above_75p_* nb_constit, by(morani_bloc)
foreach crop in cott maiz sugc toba {
	gen share_above_75p_`crop' = (above_75p_`crop' / nb_constit)*100
}
keep morani_bloc share*
rename share_above_75p_* *
gen spemeasure = "Northern-Copperbelt, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 1
replace spemeasure = "Southern, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 2
duplicates drop
tempfile 1a
save `1a'
restore
*
foreach crop in cott maiz sugc toba {
// above 75p, unconditional distribution of specialisation ratio
	sum areal_unit_`crop', d
	gen above_75p_`crop' = 1 if areal_unit_`crop' > `r(p75)'
	recode above_75p_`crop' (.=0)
}
gen nb_constit = 1
collapse (sum) above_75p_* nb_constit, by(morani_bloc)
foreach crop in cott maiz sugc toba {
	gen share_above_75p_`crop' = (above_75p_`crop' / nb_constit)*100
}
keep morani_bloc share*
rename share_above_75p_* *
gen spemeasure = "Northern-Copperbelt, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 1
replace spemeasure = "Southern, (a) Specialisation (% top-producing constituencies)" if morani_bloc == 2
duplicates drop
*
append using `1a'
*
drop morani_bloc
order spemeasure
// the dataset has been transformed to show contents of the table

*** APPENDIX Table B4 - Correlation between constituency-level total production and share of population employed in agriculture
use "Zambia_blocs_prod_info", clear
global croplist cott maiz sugc toba
local i = 0
mat A = J(2,4,.)

foreach crop in $croplist {
	local i = `i' + 1
	pwcorr total_`crop' agric ,sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[1,`i'] = C[2,1]
	mat A[2,`i'] = sig[2,1]
}
matrix colnames A = Cotton Maize Sugarcane Tobacco
matrix rownames A = Share_agric P-value
mat list A

** B3 || Results on vote shares and ethnic make-up 
*** APPENDIX Table B5 - Correlation between constituency-level vote shares for bloc winner and constituency-level share of the ethnic group that is the majority in the bloc, by bloc and election year

**** KENYA
* 1 || Dataset with constituency-level info vote share for bloc winner
use "Kenya_electoral_data.dta", clear
*
preserve
local year 1997
gen year = `year'
gen winner_share = votes_dp_`year' if winner_name_`year' == "DP"
replace winner_share = votes_kanu_`year' if winner_name_`year' == "KANU"
replace winner_share = votes_ndpk_`year' if winner_name_`year' == "NDPK"
replace winner_share = votes_sdp_`year' if winner_name_`year' == "SDP" 
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2002
gen year = `year'
gen winner_share = votes_narc_`year' if winner_name_`year' == "NARC"
replace winner_share = votes_kanu_`year' if winner_name_`year' == "KANU"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2007
gen year = `year'
gen winner_share = votes_pnu_`year' if winner_name_`year' == "PNU"
replace winner_share = votes_odm_`year' if winner_name_`year' == "ODM"
replace winner_share = votes_odmk_`year' if winner_name_`year' == "ODM-K"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2013
gen year = `year'
gen winner_share = votes_pres_kenyatta_`year' if winner_name_`year' == "pres_kenyatta"
replace winner_share = votes_pres_odinga_`year' if winner_name_`year' == "pres_odinga"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2017
gen year = `year'
gen winner_share = votes_pres_kenyatta_`year' if winner_name_`year' == "pres_kenyatta"
replace winner_share = votes_pres_odinga_`year' if winner_name_`year' == "pres_odinga"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
use `t1997', clear 
foreach year in 2002 2007 2013 2017 {
append using `t`year''
}
merge m:1 morani_bloc year using "Kenya_bloc_winners", nogen
drop if morani_bloc == 99 // non-bloc constituencies not included
keep if winner_name == winner_bloc
drop winner_bloc winner_name 
reshape wide winner_share, i(global_id) j(year)
keep global_id winner*
* 2 || Add info on constituency-level share of the ethnic group that is the majority in the bloc
merge 1:1 global_id using "Kenya_blocs_prod_info", nogen
drop if morani_bloc == 99 // non-bloc constituencies not included
// compute share of the ethnic majority at bloc level within each constituency
gen largest_gp = kikuyu if central == 1
replace largest_gp = kalenjin if rift_valley == 1
replace largest_gp = luo if western == 1
replace largest_gp = kamba if eastern == 1
replace largest_gp = largest_gp * 100
*
mat A = J(8,5,.)
local i = 0
foreach year in 1997 2002 2007 2013 2017 {
	local i = `i' + 1
	pwcorr winner_share`year' largest_gp if morani_bloc == 1, sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[1,`i'] = C[2,1]
	mat A[2,`i'] = sig[2,1]
}
local i = 0
foreach year in 1997 2002 2007 2013 2017 {
	local i = `i' + 1
	pwcorr winner_share`year' largest_gp if morani_bloc == 2, sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[3,`i'] = C[2,1]
	mat A[4,`i'] = sig[2,1]
}
local i = 0
foreach year in 1997 2002 2007 2013 2017 {
	local i = `i' + 1
	pwcorr winner_share`year' largest_gp if morani_bloc == 3, sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[5,`i'] = C[2,1]
	mat A[6,`i'] = sig[2,1]
}
local i = 0
foreach year in 1997 2002 2007 2013 2017 {
	local i = `i' + 1
	pwcorr winner_share`year' largest_gp if morani_bloc == 4, sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[7,`i'] = C[2,1]
	mat A[8,`i'] = sig[2,1]
}
matrix colnames A = 1997 2002 2007 2013 2017
matrix rownames A = Central_corr P-value Eastern_corr P-value RV_corr P-value Western_corr P-value
mat list A
// results displayed in matrix

**** MALAWI
* 1 || Dataset with constituency-level info vote share for bloc winner
use "Malawi_electoral_data.dta", clear
*
preserve
local year 1999
gen year = `year'
gen winner_share = votes_mcp_a_`year' if winner_name_`year' == "mcp-aford"
replace winner_share = votes_udf_`year' if winner_name_`year' == "udf"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2004
gen year = `year'
gen winner_share = votes_mcp_`year' if winner_name_`year' == "mcp"
replace winner_share = votes_udf_`year' if winner_name_`year' == "udf"
replace winner_share = votes_mgwirizano_`year' if winner_name_`year' == "mgwirizano"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2009
gen year = `year'
gen winner_share = votes_mcp_`year' if winner_name_`year' == "mcp"
replace winner_share = votes_dpp_`year' if winner_name_`year' == "dpp"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2014
gen year = `year'
gen winner_share = votes_mcp_`year' if winner_name_`year' == "mcp"
replace winner_share = votes_dpp_`year' if winner_name_`year' == "dpp"
replace winner_share = votes_udf_`year' if winner_name_`year' == "udf"
replace winner_share = votes_pp_`year' if winner_name_`year' == "pp"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2020
gen year = `year'
gen winner_share = votes_mcp_`year' if winner_name_`year' == "mcp"
replace winner_share = votes_dpp_`year' if winner_name_`year' == "dpp"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
use `t1999', clear 
foreach year in 2004 2009 2014 2020 {
append using `t`year''
}
*
merge m:1 morani_bloc year using "Malawi_bloc_winners", nogen
drop if morani_bloc == 99 // non-bloc constituencies not included
keep if winner_name == winner_bloc
drop winner_bloc winner_name 
reshape wide winner_share, i(global_id) j(year)
keep global_id winner*
* 2 || Add info on constituency-level share of the ethnic group that is the majority in the bloc
merge 1:1 global_id using "Malawi_blocs_prod_info", nogen
drop if morani_bloc == 99 // non-bloc constituencies not included
// compute share of the ethnic majority at bloc level within each constituency
gen largest_gp = chewa if central == 1
replace largest_gp = lomwe if southern == 1
replace largest_gp = tumbuka if northern == 1
replace largest_gp = yao if eastern == 1
replace largest_gp = largest_gp * 100

*
mat A = J(8,5,.)
local i = 0
foreach year in 1999 2004 2009 2014 2020 {
	local i = `i' + 1
	pwcorr winner_share`year' largest_gp if morani_bloc == 1, sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[1,`i'] = C[2,1]
	mat A[2,`i'] = sig[2,1]
}
local i = 0
foreach year in 1999 2004 2009 2014 2020 {
	local i = `i' + 1
	pwcorr winner_share`year' largest_gp if morani_bloc == 2, sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[3,`i'] = C[2,1]
	mat A[4,`i'] = sig[2,1]
}
local i = 0
foreach year in 1999 2004 2009 2014 2020 {
	local i = `i' + 1
	pwcorr winner_share`year' largest_gp if morani_bloc == 3, sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[5,`i'] = C[2,1]
	mat A[6,`i'] = sig[2,1]
}
local i = 0
foreach year in 1999 2004 2009 2014 2020 {
	local i = `i' + 1
	pwcorr winner_share`year' largest_gp if morani_bloc == 4, sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[7,`i'] = C[2,1]
	mat A[8,`i'] = sig[2,1]
}
matrix colnames A = 1999 2004 2009 2014 2020
matrix rownames A = Central_corr P-value Eastern_corr P-value Northern_corr P-value Southern_corr P-value
mat list A
// results displayed in matrix

**** ZAMBIA 
* 1 || Dataset with constituency-level info vote share for bloc winner
use "Zambia_electoral_data.dta", clear
*
preserve
local year 1991
gen year = `year'
gen winner_share = votes_mmd_`year' if winner_name_`year' == "mmd"
replace winner_share = votes_unip_`year' if winner_name_`year' == "unip"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 1996
gen year = `year'
gen winner_share = votes_mmd_`year' if winner_name_`year' == "mmd"
replace winner_share = votes_unip_`year' if winner_name_`year' == "unip"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2001
gen year = `year'
gen winner_share = votes_mmd_`year' if winner_name_`year' == "mmd"
replace winner_share = votes_unip_`year' if winner_name_`year' == "unip"
replace winner_share = votes_upnd_`year' if winner_name_`year' == "upnd"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2006
gen year = `year'
gen winner_share = votes_mmd_`year' if winner_name_`year' == "mmd"
replace winner_share = votes_upnd_`year' if winner_name_`year' == "upnd"
replace winner_share = votes_pf_`year' if winner_name_`year' == "pf"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2011
gen year = `year'
gen winner_share = votes_mmd_`year' if winner_name_`year' == "mmd"
replace winner_share = votes_upnd_`year' if winner_name_`year' == "upnd"
replace winner_share = votes_pf_`year' if winner_name_`year' == "pf"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2016
gen year = `year'
gen winner_share = votes_mmd_`year' if winner_name_`year' == "mmd"
replace winner_share = votes_upnd_`year' if winner_name_`year' == "upnd"
replace winner_share = votes_pf_`year' if winner_name_`year' == "pf"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
preserve
local year 2021
gen year = `year'
gen winner_share = votes_upnd_`year' if winner_name_`year' == "upnd"
replace winner_share = votes_pf_`year' if winner_name_`year' == "pf"
rename winner_name_`year' winner_name
keep global_id morani_bloc winner_name year winner_share
tempfile t`year'
save `t`year''
restore
*
use `t1991', clear 
foreach year in 1996 2001 2006 2011 2016 2021 {
append using `t`year''
}
*
merge m:1 morani_bloc year using "Zambia_bloc_winners", nogen
drop if morani_bloc == 99 // non-bloc constituencies not included
keep if winner_name == winner_bloc
drop winner_bloc winner_name 
reshape wide winner_share, i(global_id) j(year)
keep global_id winner*
* 2 || Add info on constituency-level share of the ethnic group that is the majority in the bloc
merge 1:1 global_id using "Zambia_blocs_prod_info", nogen
drop if morani_bloc == 99 // non-bloc constituencies not included
// compute share of the ethnic majority at bloc level within each constituency
gen largest_gp = tonga if southern == 1
replace largest_gp = bemba if northern_copperbelt == 1
replace largest_gp = largest_gp * 100
*
mat A = J(4,7,.)
local i = 0
foreach year in 1991 1996 2001 2006 2011 2016 2021 {
	local i = `i' + 1
	pwcorr winner_share`year' largest_gp if morani_bloc == 1, sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[1,`i'] = C[2,1]
	mat A[2,`i'] = sig[2,1]
}
local i = 0
foreach year in 1991 1996 2001 2006 2011 2016 2021 {
	local i = `i' + 1
	pwcorr winner_share`year' largest_gp if morani_bloc == 2, sig
	mat C = r(C)
	mat sig = r(sig)
	mat A[3,`i'] = C[2,1]
	mat A[4,`i'] = sig[2,1]
}

matrix colnames A = 1991 1996 2001 2006 2011 2016 2021
matrix rownames A = Northern-C_corr P-value Southern_corr P-value
mat list A
// results displayed in matrix
